package com.example.demoknife4j.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demoknife4j.model.Person;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 赵恒
 * @date 2023/5/11
 */
@RestController
@RequestMapping("/person")
@Slf4j
@Api(tags = "人物类接口")
public class PersonController {

    @GetMapping("/list/{id}")
    @ApiOperation(value = "查询ID对应的人物", notes = "根据id查询人物")
    public List<Person> list(@ApiParam( value = "人物ID", defaultValue = "1", required = true) @PathVariable Integer id) {
        log.info("id:{}", id);
        return new ArrayList<>();
    }

    @GetMapping("/list/condition")
    public List<Person> list(@RequestParam(name = "ID", defaultValue = "1") Integer id,
                             @RequestParam(name = "出生日期", defaultValue = "2023-05-11")@DateTimeFormat(pattern = "yyyy-MM-dd") Date birthDay) {
        log.info("id:{}, birthday:{}", id, birthDay);
        return new ArrayList<>();
    }

    @PostMapping("/list/map")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "人物ID", required = true, paramType = "int"),
            @ApiImplicitParam(name = "birthday", value = "生日", required = false, paramType = "date")
    })
    @ApiIgnore
    public List<Person> list(@RequestBody Map<String, Object> map) {
        log.info("map:{}", map);
        return new ArrayList<>();
    }



    @PostMapping("/insert")
    public int insert(@RequestBody Person person) {
        log.info("person:{}", JSONObject.toJSONString(person));
        return 1;
    }
}
